package cn.eeepay.framework.dao.workOrder;


import cn.eeepay.framework.model.workOrder.WorkProductConfigEntity;
import org.apache.ibatis.annotations.*;

/**
 * 工单业务配置表
 *
 * @author quanhz
 * @email
 * @date 2020-08-20 09:01:59
 */
public interface WorkProductConfigDao {

    @Select("select * from `work_product_config`")
    @ResultType(WorkProductConfigEntity.class)
    WorkProductConfigEntity getById(Long id);

    @Insert("INSERT INTO `work_product_config`( `work_product_type`, `work_type_list`,  " +
            "`team_id_list`, `warning_switch`, `warning_config`, `create_time`, `last_update_time`, `operator`) " +
            "VALUES ( #{info.workProductType}, #{info.workTypeList}," +
            " #{info.teamIdList}, #{info.warningSwitch}, #{info.warningConfig}, now(), now(), #{info.operator})")
    @SelectKey(statement = "select LAST_INSERT_ID()", keyProperty = "info.id", before = false, resultType = Long.class)
    int save(@Param("info") WorkProductConfigEntity info);

    @Update("UPDATE `work_product_config` SET " +
            " `work_type_list` = #{info.workTypeList}," +
            "  `warning_switch` = #{info.warningSwitch}," +
            " `warning_config` = #{info.warningConfig}," +
            "  `operator` = #{info.operator} WHERE `id` = #{info.id}")
    int updateById(@Param("info") WorkProductConfigEntity info);

    @Select("select * from work_product_config limit 1")
    @ResultType(WorkProductConfigEntity.class)
    WorkProductConfigEntity getDefaultconfig();

    @Select("select find_in_set(#{workTypeId},work_type_list) from work_product_config  limit 1 ")
    @ResultType(Integer.class)
    int checkOrderType(@Param("workTypeId") String workTypeId);

    @Select("select * from work_product_config  where find_in_set(#{workTypeId},work_type_list)>0 limit 1")
    @ResultType(WorkProductConfigEntity.class)
    WorkProductConfigEntity getWorkProductType(Long workTypeId);
}
